package com.qc.dao.impl;

import javax.annotation.Resource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.qc.common.StringUtil;
import com.qc.dao.KetubbahDao;
import com.qc.entity.Ketubbah;

@SuppressWarnings({ "unchecked", "rawtypes" })
@Repository("ketubbahDao")
public class KetubbahImpl implements KetubbahDao{

	@Resource(name="jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public int saveKetubbah(Ketubbah ketubbah) {
		
		String sql = "insert into t_ketubbah(user_id,money,type) values(?,?,?)";
		
		return jdbcTemplate.update(sql,new Object[]{ketubbah.getUserId(),ketubbah.getMoney(),ketubbah.getType()});
	}

	@Override
	public Ketubbah getKetubbah(String userId) {
		
		String sql = "select t_id,user_id,money,type from t_ketubbah where 1 = 1 and if_del = '0'";
		
		if (StringUtil.isNotEmpty(userId) && !"undefined".equals(userId) ) {
            sql += " and user_id = '"+userId+"' ";
        }
		return (Ketubbah) jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper(Ketubbah.class));
	}

}
